home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** Program: CShell
- ** File: AppleEvents2.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1991 Apple Computer, Inc.
- ** All rights reserved.
- **
- ** This is the custom AppleEvents code. The required AppleEvents code is in
- ** the file AppleEvents.c, which is Keith Rollin's work.
- */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "CShell.h" /* Get the CShell includes/typedefs, etc. */
- #include "CShellCommon.h" /* Get the stuff in common with rez. */
- #include "CShell.protos" /* Get the prototypes for CShell. */
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __NOTIFICATION__
- #include <Notification.h>
- #endif
-
- #ifndef __OSUTILS__
- #include <OSUtils.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __SOUND__
- #include <Sound.h>
- #endif
-
- #ifndef __STRING__
- #include <String.h>
- #endif
-
- #ifndef __SYSEQU__
- #include <SysEqu.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __TEXTEDITCONTROL__
- #include "TextEditControl.h"
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
-
-
- /*****************************************************************************/
-
-
-
- #define PRIORITY kAENormalPriority
- #define kTimeOutInTicks (60 * 30) /* 30 second timeout. */
-
-
-
- /*****************************************************************************/
-
-
-
- extern Boolean gHasAppleEvents;
- extern Boolean gHasPPCToolbox;
-
- extern RgnHandle gCurrentCursorRgn;
- extern Cursor *gCurrentCursor;
-
- static pascal OSErr DoAEAnswer(AppleEvent *message, AppleEvent *reply, long refcon);
- static pascal OSErr ReceiveConnect(AppleEvent *message, AppleEvent *reply, long refcon);
- static pascal OSErr ReceiveConnectReply(AppleEvent *message, AppleEvent *reply);
- static pascal OSErr ReceiveMessage(AppleEvent *message, AppleEvent *reply, long refcon);
- static pascal Boolean AEPortFilter(LocationNamePtr locationName, PortInfoPtr thePortInfo);
-
-
-
- /*****************************************************************************/
-
-
-
- struct triplets{
- AEEventClass theEventClass;
- AEEventID theEventID;
- ProcPtr theHandler;
- };
- typedef struct triplets triplets;
- static triplets keywordsToInstall[] = {
- { kCoreEventClass, kAEAnswer, (ProcPtr) DoAEAnswer },
- { kCustomEventClass, keyAppConnect, (ProcPtr) ReceiveConnect },
- { kCustomEventClass, keyAppMessage, (ProcPtr) ReceiveMessage }
- }; /* These are the custom AppleEvents. */
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* InitCustomAppleEvents
- **
- ** Install our custom AppleEvents. This is done in addition to installing
- ** the required AppleEvents. InitAppleEvents, which installs the required
- ** AppleEvents, must be called first, since it sets up some global values.
- */
-
- #pragma segment AppleEvents
- void InitCustomAppleEvents(void)
- {
- OSErr err;
- short i;
-
- if (gHasAppleEvents) {
- for (i = 0; i < (sizeof(keywordsToInstall) / sizeof(triplets)); ++i) {
- err = AEInstallEventHandler(
- keywordsToInstall[i].theEventClass, /* What class to install. */
- keywordsToInstall[i].theEventID, /* Keywords to install. */
- keywordsToInstall[i].theHandler, /* The AppleEvent handler. */
- 0L, /* Unused refcon. */
- false /* Only for our app. */
- );
-
- if (err) {
- Alert(rErrorAlert, nil);
- return;
- }
- }
- }
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment AppleEvents
- pascal OSErr DoAEAnswer(AppleEvent *message, AppleEvent *reply, long refcon)
- {
- #pragma unused (refcon)
-
- OSErr err;
-
- gCurrentCursor = nil;
- /* Force re-calc of cursor region and cursor to use. */
-
- err = ReceiveConnectReply(message, reply);
-
- AEPutParamPtr( /* RETURN REPLY ERROR, EVEN IF NONE... */
- reply, /* The AppleEvent. */
- keyReplyErr, /* AEKeyword */
- typeShortInteger, /* Desired type. */
- (Ptr)&err, /* Pointer to area for data. */
- sizeof(short) /* Size of data area. */
- );
-
- return(noErr);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* SendConnect
- **
- */
-
- #pragma segment AppleEvents
- OSErr SendConnect(FileRecHndl frHndl)
- {
- AEAddressDesc remoteUserLoc;
- OSErr err;
- long windID[2], size;
- char hstate;
- Ptr ptr1, ptr2;
- AppleEvent theAevt, reply;
- Str255 macText, appText, userName;
- Handle userNameHndl;
- FSSpec myFSS;
- short i;
-
- theAevt.dataHandle = reply.dataHandle = nil;
- /* Make sure disposing of the descriptors is okay in all cases.
- ** This will not be necessary after 7.0b3, since the calls that
- ** attempt to create the descriptors will nil automatically
- ** upon failure. */
-
- err = noErr;
- /* We may not make the first operation that can cause an error,
- ** so we have to initialize err. */
-
- remoteUserLoc.dataHandle = nil;
- /* Make it safe to dispose of in all cases. */
-
- GetIndString(macText, rPPCText, sTitleText);
- GetIndString(appText, rPPCText, sAppText);
- err = MakeTarget(&remoteUserLoc, false, kAEWaitReply,
- macText, appText, (PPCFilterProcPtr) AEPortFilter);
- /* Generate the target for the remote user. */
- (*frHndl)->doc.windowID[0] = windID[0] = TickCount();
- (*frHndl)->doc.windowID[1] = windID[0];
- (*frHndl)->doc.remoteUserLoc = remoteUserLoc;
-
- if (!err) { /* Create the AppleEvent... */
- err = AECreateAppleEvent( /* CREATE EMPTY APPLEEVENT. */
- kCustomEventClass, /* Event class. */
- typeAppConnect, /* Event ID. */
- &remoteUserLoc, /* Address of receiving app. */
- kAutoGenerateReturnID, /* This value causes the */
- /* AppleEvent manager to */
- /* assign a return ID that */
- /* is unique to the session. */
- kAnyTransactionID, /* Ignore transaction ID. */
- &theAevt /* Location of event. */
- );
- }
-
- if (!err) { /* If we have an empty list to add to... */
- hstate = LockHandleHigh((Handle)frHndl);
- ptr1 = (Ptr)&((*frHndl)->doc);
- ptr2 = (Ptr)&((*frHndl)->doc.endSendInfo);
- size = (long)ptr2 - (long)ptr1;
- err = AEPutParamPtr( /* ADD FILE INFO TO THE APPLEEVENT. */
- &theAevt, /* AppleEvent to add to. */
- keyAppConnect, /* AEKeyword. */
- typeAppConnect, /* Desired type. */
- ptr1, /* Pointer to the data to be sent. */
- (Size) size /* Size of the data to be sent. */
- );
- HSetState((Handle)frHndl, hstate);
- }
-
- if (!err) {
- myFSS = (*frHndl)->fileState.fss;
- err = AEPutParamPtr( /* ADD WINDOW NAME TO APPLEEVENT. */
- &theAevt, /* AppleEvent to add to. */
- keyFSS, /* AEKeyword. */
- typeKFSS, /* Desired type. */
- (Ptr)&myFSS, /* Pointer to the data. */
- sizeof(FSSpec) /* Size of the data. */
- );
- }
-
- if (!err) {
- userName[0] = 0;
- if (userNameHndl = GetResource('STR ', -16096))
- pstrcpy((char *) &userName, (char *)(*userNameHndl));
- err = AEPutParamPtr( /* ADD USER NAME TO APPLEEVENT. */
- &theAevt, /* AppleEvent to add to. */
- keyPascal, /* AEKeyword. */
- typePascal, /* Desired type. */
- (Ptr) userName, /* Pointer to the data. */
- (Size) userName[0] + 1 /* Size of the data. */
- );
- }
-
- if (!err) { /* If we have an AppleEvent ready to send... */
- err = AESend( /* SEND APPLEEVENT. */
- &theAevt, /* Our Apple Event to send. */
- &reply, /* We may have a reply. */
- kAEQueueReply, /* Type of reply. */
- PRIORITY, /* App. send priority. */
- 0, /* We aren't waiting. */
- nil, /* We aren't waiting. */
- nil /* EventFilterProcPtr. */
- );
- }
- if (remoteUserLoc.descriptorType == typeProcessSerialNumber)
- err = ReceiveConnectReply(&reply, &reply);
- /* If we want q queue reply, and if we are sending to ourselves,
- ** then we already have the reply. Since we are sending to
- ** ourselves, we don't have to wait for an event. Stuff happens
- ** right away. We're (probably) happy. */
-
- AEDisposeDesc(&theAevt);
- AEDisposeDesc(&reply);
- /* Dispose of the descriptors, created or not.
- ** If not created, no harm done by calling. */
-
- if (err) {
- AEDisposeDesc(&remoteUserLoc);
- /* If we didn't connect, get rid of the target descriptor. */
-
- for (i = 0; i < 2; ++i) (*frHndl)->doc.windowID[i] = 0;
- /* Mark this window so that it will never be found if we somehow
- ** do get an answer from the receiver, even after failure. */
- }
-
- return(err);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* ReceiveConnect
- **
- */
-
- #pragma segment AppleEvents
- pascal OSErr ReceiveConnect(AppleEvent *message, AppleEvent *reply, long refcon)
- {
- #pragma unused (refcon)
-
- OSErr err;
- FileRecHndl frHndl;
- char hstate;
- Ptr ptr1, ptr2;
- long size, windID[2];
- AEAddressDesc senderTarget;
- DescType ignoredType;
- Size ignoredSize;
- FSSpec myFSS;
- Str255 userName;
- Handle userNameHndl;
-
- err = noErr;
- AEPutParamPtr( /* RETURN REPLY ERROR, EVEN IF NONE... */
- reply, /* The AppleEvent. */
- keyReplyErr, /* AEKeyword */
- typeShortInteger, /* Desired type. */
- (Ptr)&err, /* Pointer to area for data. */
- sizeof(short) /* Size of data area. */
- );
-
- IncNewFileNum(false);
- err = AppNewDocument(&frHndl);
- IncNewFileNum(true);
-
- if (err) return(err);
-
- if (!err) {
- hstate = LockHandleHigh((Handle)frHndl);
- ptr1 = (Ptr)&((*frHndl)->doc);
- ptr2 = (Ptr)&((*frHndl)->doc.endSendInfo);
- size = (long)ptr2 - (long)ptr1;
- err = AEGetParamPtr( /* GET CONNECT INFO FROM THE APPLEEVENT. */
- message, /* The AppleEvent. */
- keyAppConnect, /* AEKeyword */
- typeAppConnect, /* Desired type. */
- &ignoredType, /* Type code. */
- ptr1, /* Pointer to area for data. */
- size, /* Size of data area. */
- &ignoredSize /* Returned size of data. */
- );
- HSetState((Handle)frHndl, hstate);
- }
-
- if (!err) {
- err = AEGetAttributeDesc( /* GET ADDRESS OF SENDER. */
- message, /* Get address of sender from message. */
- keyAddressAttr, /* We want an address. */
- typeWildCard, /* We want the address of the sender. */
- &senderTarget /* Address of sender. */
- );
- if (!err) {
- (*frHndl)->doc.remoteUserLoc = senderTarget;
- err = AEGetParamPtr( /* GET FSSpec (FOR WINDOW NAME) FROM APPLEEVENT. */
- message, /* The AppleEvent. */
- keyFSS, /* AEKeyword */
- typeKFSS, /* Desired type. */
- &ignoredType, /* Type code. */
- (Ptr)&myFSS, /* Pointer to area for data. */
- sizeof(FSSpec), /* Size of the data. */
- &ignoredSize /* Returned size of data. */
- );
- if (!err)
- pstrcpy((char *) &(*frHndl)->fileState.fss.name, (char *) &myFSS.name);
- }
- if (!err) {
- err = AEGetParamPtr( /* GET USER NAME FROM APPLEEVENT. */
- message, /* The AppleEvent. */
- keyPascal, /* AEKeyword */
- typePascal, /* Desired type. */
- &ignoredType, /* Type code. */
- (Ptr) userName, /* Pointer to area for data. */
- sizeof(Str255), /* Size of the data. */
- &ignoredSize /* Returned size of data. */
- );
- (*frHndl)->doc.remoteUserName[0] = 0;
- if (!err)
- pstrcpy((char *) &(*frHndl)->doc.remoteUserName, (char *) &userName);
- }
- }
-
- if (!err) { /* If we got the remote user address... */
-
- (*frHndl)->doc.windowID[0] = windID[0] = TickCount();
- (*frHndl)->doc.connected = true;
-
- if ((*frHndl)->doc.version != kVersion) err = errAEWrongDataType;
- /* Incompatible file format. */
-
- if (!err) {
- windID[1] = (*frHndl)->doc.windowID[1];
- err = AEPutParamPtr( /* RETURN RECEIVER WINDOW ID. */
- reply, /* The AppleEvent. */
- keyWindowID, /* AEKeyword */
- typeDoubleLong, /* Type code. */
- (Ptr)&windID[0], /* Pointer to area for data. */
- 2 * sizeof(long) /* Size of data area. */
- );
- }
-
- if (!err) {
- userName[0] = 0;
- if (userNameHndl = GetResource('STR ', -16096))
- pstrcpy((char *) &userName, (char *)(*userNameHndl));
- err = AEPutParamPtr( /* RETURN RECEIVER USER NAME. */
- reply, /* The AppleEvent. */
- keyPascal, /* AEKeyword */
- typePascal, /* Type code. */
- (Ptr) userName, /* Pointer to area for data. */
- userName[0] + 1 /* Size of data area. */
- );
- }
-
- if (!err) err = AppNewWindow(frHndl, nil);
- /* If connecting worked, create a window for the document. */
- }
-
- if (err) AppDisposeDocument(frHndl);
-
- if (!err) NotifyUser();
- return(err);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment AppleEvents
- pascal OSErr ReceiveConnectReply(AppleEvent *message, AppleEvent *reply)
- {
- #pragma unused (reply)
-
- OSErr err, replyErr;
- DescType actualType;
- long windID[2], actualSize;
- WindowPtr window;
- FileRecHndl frHndl;
- Str255 userName;
-
- err = AEGetParamPtr( /* CHECK FOR A RECEIVER ERROR... */
- message, /* The AppleEvent. */
- keyReplyErr, /* AEKeyword */
- typeShortInteger, /* Desired type. */
- &actualType, /* Type code. */
- (Ptr)&replyErr, /* Pointer to area for data. */
- sizeof(short), /* Size of data area. */
- &actualSize /* Returned size of data. */
- );
- if (!err) err = replyErr;
-
- if (!err) {
- err = AEGetParamPtr( /* GET RECEIVER WINDOW ID. */
- message, /* The AppleEvent. */
- keyWindowID, /* AEKeyword */
- typeDoubleLong, /* Desired type. */
- &actualType, /* Type code. */
- (Ptr)&windID[0], /* Pointer to area for data. */
- 2 * sizeof(long), /* Size of data area. */
- &actualSize /* Returned size of data. */
- );
- }
-
- if (!err) { /* If we got the receiver window ID... */
-
- window = GetAEWindow(windID[1], windID[1]);
- /* The ID's are still both ours, since this is where we
- ** get the receiver's ID returned. windID[0] holds the
- ** receiver's ID, and windID[1] holds ours. */
-
- if (window) {
- frHndl = (FileRecHndl)GetWRefCon(window);
- if (!(*frHndl)->doc.connected) {
- err = AEGetParamPtr(
- message, /* The AppleEvent. */
- keyPascal, /* AEKeyword */
- typePascal, /* Desired type. */
- &actualType, /* Type code. */
- (Ptr) userName, /* Pointer to area for data. */
- sizeof(Str255), /* Size of data area. */
- &actualSize /* Returned size of data. */
- );
-
- (*frHndl)->doc.remoteUserName[0] = 0;
- if (!err) {
- (*frHndl)->doc.windowID[1] = windID[0];
- pstrcpy((char *) &(*frHndl)->doc.remoteUserName[0], (char *) &userName);
- (*frHndl)->doc.connected = true;
- }
- else
- (*frHndl)->doc.windowID[0] = (*frHndl)->doc.windowID[1] = 0;
- }
- }
- }
-
- return(err);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* SendMessage
- **
- */
-
- #pragma segment AppleEvents
- OSErr SendMessage(FileRecHndl frHndl, short messageType)
- {
- AEAddressDesc remoteUserLoc;
- OSErr err;
- TEHandle te;
- char hstate;
- AppleEvent theAevt, reply;
- Handle hText;
- long size, windID[2];
- short i;
- WindowPtr oldPort;
-
- if (!(*frHndl)->doc.connected) return(noErr);
-
- oldPort = SetFilePort(frHndl);
-
- theAevt.dataHandle = reply.dataHandle = nil;
- /* Make sure disposing of the descriptors is okay in all cases.
- ** This will not be necessary after 7.0b3, since the calls that
- ** attempt to create the descriptors will nil automatically
- ** upon failure. */
-
- remoteUserLoc = (*frHndl)->doc.remoteUserLoc;
-
- err = AECreateAppleEvent( /* CREATE EMPTY APPLEEVENT. */
- kCustomEventClass, /* Event class. */
- typeAppMessage, /* Event ID. */
- &remoteUserLoc, /* Address of receiving app. */
- kAutoGenerateReturnID, /* This value causes the */
- /* AppleEvent manager to */
- /* assign a return ID that */
- /* is unique to the session. */
- kAnyTransactionID, /* Ignore transaction ID. */
- &theAevt /* Location of event. */
- );
-
- if (!err) { /* Say what the message is. */
- AEPutParamPtr(
- &theAevt,
- keyDirectObject,
- typeShortInteger,
- (Ptr)&messageType,
- sizeof(short)
- );
- }
-
- if (!err) { /* Say what window message is for. */
- for (i = 0; i < 2; ++i) windID[i] = (*frHndl)->doc.windowID[i];
- AEPutParamPtr(
- &theAevt,
- keyWindowID,
- typeDoubleLong,
- (Ptr)&windID[0],
- 2 * sizeof(long)
- );
- }
-
- /* The stuff that applies to all messages is now done. Now specifically
- ** handle all the different message types. */
-
- if (!err) {
- switch (messageType) {
-
- case kDisconnectMssg:
- /* All the information we need is already in the AppleEvent. */
- break;
-
- case kTextMssg:
- te = (*frHndl)->doc.outBox;
- hText = (*te)->hText;
- hstate = LockHandleHigh(hText);
- size = (*te)->teLength;
- err = AEPutParamPtr(
- &theAevt,
- keyAppMessage,
- typeTextMessage,
- *hText,
- size
- );
- HSetState(hText, hstate);
- break;
- }
- }
-
- if (!err) { /* If everything looks good... */
- err = AESend( /* SEND APPLEEVENT. */
- &theAevt, /* Our Apple Event to send. */
- &reply, /* We may have a reply. */
- kAENoReply, /* Don't wait for reply. */
- PRIORITY, /* App. send priority. */
- 0, /* We aren't waiting. */
- (IdleProcPtr)MyIdleProc, /* Our only shot at doing some */
- /* work if we are waiting. */
- nil /* EventFilterProcPtr. */
- );
- }
-
- if (!err) {
- if (messageType == kTextMssg)
- CTESetSelect(0, (*te)->teLength, te);
- /* Select all the text so entering the next message
- ** is more convenient. */
- }
-
- AEDisposeDesc(&theAevt);
- AEDisposeDesc(&reply);
- /* Dispose of the descriptors, created or not.
- ** If not created, no harm done by calling. */
-
- SetPort(oldPort);
- return(err);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment AppleEvents
- pascal OSErr ReceiveMessage(AppleEvent *message, AppleEvent *reply, long refcon)
- {
- #pragma unused (refcon)
-
- OSErr err;
- short messageType;
- WindowPtr window;
- FileRecHndl frHndl;
- DescType actualType;
- long actualSize, mssgSize, windID[2];
- char hstate;
- Handle mssgData;
- AEAddressDesc remoteUserLoc;
-
- err = noErr;
- AEPutParamPtr( /* RETURN REPLY ERROR, EVEN IF NONE... */
- reply, /* The AppleEvent. */
- keyReplyErr, /* AEKeyword */
- typeShortInteger, /* Desired type. */
- (Ptr)&err, /* Pointer to area for data. */
- sizeof(short) /* Size of data area. */
- );
-
- err = AEGetParamPtr( /* GET THE MESSAGE TYPE. */
- message, /* The AppleEvent. */
- keyDirectObject, /* AEKeyword */
- typeShortInteger, /* Desired type. */
- &actualType, /* Type code. */
- (Ptr)&messageType, /* Pointer to area for data. */
- 2 * sizeof(long), /* Size of data area. */
- &actualSize /* Returned size of data. */
- );
-
- if (!err) {
- err = AEGetParamPtr( /* GET WINDOW MESSAGE IS FOR. */
- message, /* The AppleEvent. */
- keyWindowID, /* AEKeyword */
- typeDoubleLong, /* Desired type. */
- &actualType, /* Type code. */
- (Ptr)&windID[0], /* Pointer to area for data. */
- 2 * sizeof(long), /* Size of data area. */
- &actualSize /* Returned size of data. */
- );
- }
-
- if (!err) { /* See if the requested window exists... */
- if (window = GetAEWindow(windID[1], windID[0])) {
- frHndl = (FileRecHndl)GetWRefCon(window);
- /* The window still exists... */
- }
- else
- err = userCanceledErr;
- /* User (or computer) canceled connection by disconnecting improperly. */
- }
-
- if (!err) { /* If everything is cool, then do the specific task... */
-
- switch(messageType) {
-
- case kDisconnectMssg:
- remoteUserLoc = (*frHndl)->doc.remoteUserLoc;
- AEDisposeDesc(&remoteUserLoc);
- (*frHndl)->doc.connected = false;
- AdjustMenus();
- break;
-
- case kTextMssg:
- if (!err) { /* Determine the size of the data... */
- err = AEGetParamPtr(
- message, /* The AppleEvent. */
- keyAppMessage, /* AEKeyword */
- typeTextMessage, /* Desired type. */
- &actualType, /* Type code. */
- nil, /* Pointer to area for data. */
- 0, /* Size of data area. */
- &mssgSize /* Returned size of data. */
- );
- }
- mssgData = nil;
- if (!err) { /* Get the data... */
- mssgData = NewHandle(mssgSize);
- if (mssgData) {
- hstate = LockHandleHigh(mssgData);
- err = AEGetParamPtr(
- message, /* The AppleEvent. */
- keyAppMessage, /* AEKeyword */
- typeTextMessage, /* Desired type. */
- &actualType, /* Type code. */
- *mssgData, /* Pointer to area for data. */
- mssgSize, /* Size of data area. */
- &actualSize /* Returned size of data. */
- );
- }
- else err = memFullErr;
- }
- if (!err) mssgData = CTESwapText((*frHndl)->doc.inBox, mssgData, true);
- if (mssgData) DisposHandle(mssgData);
- if (!err) NotifyUser();
- break;
-
- }
- }
-
- return(err);
- }
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* GetAEWindow
- **
- ** Find the window with the specified window ID's.
- */
-
- #pragma segment AppleEvents
- WindowPtr GetAEWindow(long windID_0, long windID_1)
- {
- WindowPeek window;
- FileRecHndl frHndl;
-
- for (window = *(WindowPeek *)WindowList; window; window = window->nextWindow) {
- if (IsAppWindow((WindowPtr)window)) {
- frHndl = (FileRecHndl)GetWRefCon((WindowPtr)window);
- if (
- ((*frHndl)->doc.windowID[0] == windID_0) &&
- ((*frHndl)->doc.windowID[1] == windID_1)
- ) return((WindowPtr)window);
- }
- }
-
- return(nil);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* MyIdleProc
- **
- ** This routine gets either an updateEvt, an activateEvt, a nullEvent or an
- ** OSEvent. The first time called it will get a nullEvent; this is its chance
- ** to set the sleep value and mouseRegion that will be passed to WaitNextEvent
- ** by the caller within the AEM. After that it will also get events of the
- ** other types (which are lost if masked out by the AEM) and must do with them
- ** whatever is appropriate.
- */
-
- #pragma segment AppleEvents
- pascal Boolean MyIdleProc(EventRecord *event, long *sleep, RgnHandle *mouseRgn)
- {
- switch (event->what) {
-
- case updateEvt:
- case activateEvt:
- case kOSEvent:
-
- /* These events are passed by the AppleEvent manager to avoid
- dropping while waiting for a reply or notification. Every
- procedure should handle these events in their idle procedure.
- In this code, we simply dispatch these events back to the
- main event loop handling code. */
-
- DoCursor(false, 0);
- DoEvent(event);
- break;
-
-
- case nullEvent:
-
- /* The idle procedure is called once with the null event before
- the loop begins. This allows the application to alter sleep
- time and mouseRgn to meet its own needs. Since we're doing
- nothing, set the cursor to a watch. */
-
- DoCursor(true, 'wait');
-
- *mouseRgn = gCurrentCursorRgn;
- *sleep = 60; /* This is just like the WaitNextEvent
- sleeptime, so use the correct value for
- your application. It's better to use a
- non-zero value here rather than zero,
- as using zero really slows you down. */
-
- /* DoIdle(); */ /* Application's idle handling. */
- break;
-
- default:
- Alert(rErrorAlert, nil);
- break;
- }
- return(false);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* AEPortFilter
- **
- ** Don't allow PPCBrowser to show any applications other than CShell.
- */
-
- #pragma segment AppleEvents
- pascal Boolean AEPortFilter(LocationNamePtr locationName, PortInfoPtr thePortInfo)
- {
- #pragma unused (locationName)
-
- long type;
-
- if (thePortInfo->name.portKindSelector == ppcByString) {
- BlockMove(thePortInfo->name.u.portTypeStr + 1, (Ptr)&type, 4);
- /* The BlockMove is so that we don't get an address error
- ** on a 68000-based machine due to referencing a long at
- ** an odd-address. */
- if (type == docCreator) return(true);
- }
-
- return(false);
- }
-
-
-
-